package com.ssyu.examination.student.service;

import java.util.ArrayList;
import java.util.List;

import com.ssyu.examination.conmmon.PageModel;
import com.ssyu.examination.conmmon.util.DBUtil;
import com.ssyu.examination.exam.entity.ExamPlanEntity;
import com.ssyu.examination.student.entity.AssistMessageEntity;

public class StudentService {

	/**
	 * 查询考试
	 */
	public PageModel<ExamPlanEntity> stuListExam(int page, int rows, int id) {
		List<Object> objects = new ArrayList<Object>();
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT exam_plan.id,exam_plan.exam_time_start,exam_plan.exam_time_stop,exam_plan.to_class_id,");
		sb.append("exam_plan.exam_classroom,exam_plan.operate_time,qes_exam_paper.`name` as qes_exam_paper__name FROM exam_plan , qes_exam_paper ,sys_user WHERE  ");
		sb.append("exam_plan.exam_time_start > NOW() AND exam_plan.exam_paper_id = qes_exam_paper.id AND sys_user.id = ? ORDER BY exam_plan.exam_time_start ASC LIMIT ?,? ");
		objects.add(id);
		objects.add((page - 1) * rows);
		objects.add(rows);
		return DBUtil.executeQueryByPage(ExamPlanEntity.class, sb.toString(),
				objects);
	}

	/**
	 * 查询站内消息
	 * 
	 * @param id
	 * @return
	 */
	public List<AssistMessageEntity> stuMessage(int id) {
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT assist_message.title, assist_message.content ");
		sb.append("FROM sys_user INNER JOIN assist_message ON sys_user.id = assist_message.receiver_user_ids ");
		sb.append("WHERE sys_user.id = assist_message.receiver_user_ids AND sys_user.id =? ");
		sb.append("ORDER BY assist_message.send_time ASC ");
		return DBUtil
				.executeQuery(AssistMessageEntity.class, sb.toString(), id);
	}
}
